package o.mrs;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class OMRSActivity extends Activity {
    
	private EditText user;
	private EditText pass;
	private Button boton;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        user=(EditText) findViewById(R.id.LoginUsr);
        pass=(EditText) findViewById(R.id.LoginPass);
        boton=(Button)  findViewById(R.id.LoginButton);	
        
        boton.setOnClickListener(new OnClickListener() {
			
 			public void onClick(View v) {
 				
 				ApiRest.setUsername(user.getText().toString());
 				ApiRest.setPassword(pass.getText().toString());
 				ApiRest.setURLBase("http://192.168.1.4:8080/openmrs/ws/rest/v1/");					
			
					try {
						if(ApiRest.comfirmSesion()){									
							Intent i = new Intent();
							i.setClass(getApplicationContext(), MainMenu.class);					
							startActivity(i);}
							
						else{
							Toast.makeText(getApplicationContext(), "Usuario invalido", Toast.LENGTH_SHORT).show();	
							}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				
 				
 			}
 		});
        
    
    }  
    
}